package cn.hicard.auth.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.auth.dao.BaseDao;
import cn.hicard.auth.dao.RoleSourceDao;
import cn.hicard.auth.entity.MgRoleSource;

/**
 * [角色-资源]管理DAO接口实现
 * @author zhangy
 *
 */
@Repository
public class RoleSourceDaoImpl extends BaseDao<MgRoleSource> implements RoleSourceDao {

	@Override
	public void saveRoleSources(List<MgRoleSource> list) throws Exception {
		// 由于资源和角色的映射数据一般比较大，这里使用批理处理
		super.save(list);
	}

	@Override
	public void deleteByRole(int pkRole) throws Exception {
		String hql = "DELETE FROM MgRoleSource WHERE id.pkRoleinfo=?";
		super.updateByHqlBulk(hql, pkRole);
	}
	
	@Override
	public List<Integer> findSourcePkByRole(int pkRoleinfo) throws Exception {
		String hql = "SELECT id.pkSource FROM MgRoleSource WHERE id.pkRoleinfo=?";
		@SuppressWarnings("unchecked")
		List<Integer> list = super.findFieldsByHql(hql, pkRoleinfo); 
		return list;
	}

}
